package com.hmjk.health.util;

import java.util.ArrayList;

public class BP_Reference {
	
	private static ArrayList<BP_REFER_VALUE> maleBpRef = new ArrayList<BP_REFER_VALUE>();
	private static ArrayList<BP_REFER_VALUE> femaleBpRef = new ArrayList<BP_REFER_VALUE>();
	private static ArrayList<AGEGROUP> ageGroup = new ArrayList<AGEGROUP>();
	
	private static BP_Reference me;
	
	/*
	 * 0:	15-22
	 * 1:	23-27
	 * 2:	28-33
	 * 3:	34-45
	 * 4:	45-55
	 * 5:	55-65
	 * 6:	66-999
	 */
	
	class BP_REFER_VALUE{
		int sbp;
		int dbp;
		
		BP_REFER_VALUE(int arg0, int arg1){
			sbp = arg0;
			dbp = arg1;
		}
	}
	
	class AGEGROUP{
		int high;
		int low;
		
		AGEGROUP(int arg0, int arg1){
			low = arg0;
			high = arg1;
		}
	}
	
	public static BP_Reference getInstance(){
		if(me == null)
			me = new BP_Reference();
		return me;
	}

	private BP_Reference() {
		maleBpRef.clear();
		femaleBpRef.clear();
		ageGroup.clear();
		
		//15-22
		AGEGROUP age = new AGEGROUP(15, 22);
		BP_REFER_VALUE mValue = new BP_REFER_VALUE(120, 78);
		BP_REFER_VALUE fValue = new BP_REFER_VALUE(115, 75);
		ageGroup.add(age);
		maleBpRef.add(mValue);
		femaleBpRef.add(fValue);
		
		//23-27
		age = new AGEGROUP(23, 27);
		mValue = new BP_REFER_VALUE(120, 78);
		fValue = new BP_REFER_VALUE(115, 76);
		ageGroup.add(age);
		maleBpRef.add(mValue);
		femaleBpRef.add(fValue);
		
		//28-33
		age = new AGEGROUP(28, 33);
		mValue = new BP_REFER_VALUE(120, 80);
		fValue = new BP_REFER_VALUE(119, 79);
		ageGroup.add(age);
		maleBpRef.add(mValue);
		femaleBpRef.add(fValue);
		
		//34-45
		age = new AGEGROUP(34, 45);
		mValue = new BP_REFER_VALUE(125, 85);
		fValue = new BP_REFER_VALUE(121, 82);
		ageGroup.add(age);
		maleBpRef.add(mValue);
		femaleBpRef.add(fValue);
		
		//46-55
		age = new AGEGROUP(46, 55);
		mValue = new BP_REFER_VALUE(133, 87);
		fValue = new BP_REFER_VALUE(133, 82);
		ageGroup.add(age);
		maleBpRef.add(mValue);
		femaleBpRef.add(fValue);
		
		//56-65
		age = new AGEGROUP(56, 65);
		mValue = new BP_REFER_VALUE(142, 89);
		fValue = new BP_REFER_VALUE(144, 87);
		ageGroup.add(age);
		maleBpRef.add(mValue);
		femaleBpRef.add(fValue);
		
		//66-999
		age = new AGEGROUP(66, 999);
		mValue = new BP_REFER_VALUE(155, 90);
		fValue = new BP_REFER_VALUE(155, 90);
		ageGroup.add(age);
		maleBpRef.add(mValue);
		femaleBpRef.add(fValue);
	}
	
	public static int[] checkAgeGroup(int age, String gendar){
		getInstance();
		
		int[] ret = new int[4];
		int index = 0;
		
		for(AGEGROUP a:ageGroup){
			if((age >= a.low) && (age <= a.high)){
				ret[0] = a.low;
				ret[1] = a.high;
				break;
			}
			index ++;
		}
		
		if(gendar.equalsIgnoreCase("m")){
			BP_REFER_VALUE v = maleBpRef.get(index);
			ret[2] = v.sbp;
			ret[3] = v.dbp;
		}else {
			BP_REFER_VALUE v = femaleBpRef.get(index);
			ret[2] = v.sbp;
			ret[3] = v.dbp;
		}
		
		return ret;
	}

}
